import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SPassPoint } from "../../../../../Message/Public/SPassPoint";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { Cache } from "../../../cache/Cache";
import { Language } from "../../../../../extend/language/Language";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
type int = number;
//class PassItem
    
    export  class PassItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._itemBody = new Object /* flash.display.Sprite */();
            addChild(this._itemBody);
            this._passBitmap = new Object /* flash.display.Bitmap */();
            this._itemBody.addChild(this._passBitmap);
            this._nameLabel = new Object /* flash.text.TextField */();
            this._nameLabel.htmlText = "";
            this._nameLabel.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._nameLabel.selectable = false;
            this._nameLabel.filters = [FilterConst.nameGlowFilter];
            this._nameLabel.selectable = false;
            this._nameLabel.defaultTextFormat = new GTextFormat(null, 12, 16777215, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            addChild(this._nameLabel);
            mouseEnabled = false;
            addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClick);
            LoaderHelp.addResCallBack(ResFileConst.mapUI, this.onMapUIResLoadedHandler);
            return;
        }

        protected onMapUIResLoadedHandler(): void
        {
            this._passBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.MapUIPass);
            this._nameLabel.x = (this._passBitmap.width - this._nameLabel.textWidth) / 2;
            this._nameLabel.y = -this._passBitmap.height;
            return;
        }

        /* internal  */onMouseClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispatchEvent(new DataEvent(EventName.PassItemClick, this._data));
            return;
        }

        public set data(arg1: SPassPoint)
        {
            this._data = arg1;
            if (this._data) 
            {
                this.updateData();
                if (this._passBitmap.bitmapData) 
                {
                    this._nameLabel.x = (this._passBitmap.width - this._nameLabel.textWidth) / 2;
                    this._nameLabel.y = -this._passBitmap.height;
                }
            }
            return;
        }

        public updateData(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            if (this._data) 
            {
                this.mouseChildren = true;
                loc1 = this._data.name;
                loc2 = "#FFFFFF";
                if (GameMapUtil.curMapState.isGuildElite) 
                {
                    loc3 = this._data.passTo && this._data.passTo.length > 0 ? this._data.passTo[0] : null;
                    if (loc3 && Cache.instance.guildElite.isMapComplete(loc3.mapId)) 
                    {
                        this.mouseChildren = false;
                        loc1 = this._data.name + "[" + Language.getString(60621) + "]";
                        loc2 = "#727B78";
                    }
                }
                this._nameLabel.htmlText = HTMLUtil.addColor(loc1, loc2);
            }
            else 
            {
                this._nameLabel.htmlText = "";
            }
            return;
        }

        public get data(): SPassPoint
        {
            return this._data;
        }

        public dispose(): void
        {
            this._data = null;
            return;
        }

        public /* override */ get width(): number
        {
            if (this._passBitmap.bitmapData) 
            {
                return this._passBitmap.width;
            }
            return 15;
        }

        public /* override */ get height(): number
        {
            if (this._passBitmap.height) 
            {
                return this._passBitmap.height;
            }
            return 15;
        }

        /* internal */ /* var */_px: int;

        /* internal */ /* var */_py: int;

        /* internal */ /* var */_data: SPassPoint;

        /* internal */ /* var */_passBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_itemBody: Object /* flash.display.Sprite */;

        /* internal */ /* var */_nameLabel: Object /* flash.text.TextField */;
    }
